package cn.stylefeng.guns.modular.basic.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.basic.entity.BasicTypeGs;
import cn.stylefeng.guns.modular.basic.mapper.BasicTypeGsMapper;
import cn.stylefeng.guns.modular.basic.model.params.BasicTypeGsParam;
import cn.stylefeng.guns.modular.basic.model.params.BasicTypeParam;
import cn.stylefeng.guns.modular.basic.model.result.BasicTypeGsResult;
import cn.stylefeng.guns.modular.basic.model.result.BasicTypeResult;
import  cn.stylefeng.guns.modular.basic.service.BasicTypeGsService;
import cn.stylefeng.guns.sys.modular.system.entity.User;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author wzh
 * @since 2024-01-12
 */
@Service
public class BasicTypeGsServiceImpl extends ServiceImpl<BasicTypeGsMapper, BasicTypeGs> implements BasicTypeGsService {

    @Override
    public void add(BasicTypeGsParam param){
        BasicTypeGs entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(BasicTypeGsParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(BasicTypeGsParam param){
        BasicTypeGs oldEntity = getOldEntity(param);
        BasicTypeGs newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public BasicTypeGsResult findBySpec(BasicTypeGsParam param){
        return null;
    }

    @Override
    public List<BasicTypeGsResult> findListBySpec(BasicTypeGsParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(BasicTypeGsParam param,String condition){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(BasicTypeGsParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private BasicTypeGs getOldEntity(BasicTypeGsParam param) {
        return this.getById(getKey(param));
    }

    private BasicTypeGs getEntity(BasicTypeGsParam param) {
        BasicTypeGs entity = new BasicTypeGs();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

    @Autowired
    private BasicTypeGsMapper basicTypeGsMapper;
    @Override
    public List<BasicTypeGsResult> list2(BasicTypeGsParam basicTypeGsParam) {
        List<BasicTypeGsResult> list = basicTypeGsMapper.List2(basicTypeGsParam);
        return list;
    }
}
